package com.robmayhew.jsc;

import com.robmayhew.jsc.Project;

import java.util.*;

/**
 * User: rmayhew
 * Date: Apr 11, 2005
 * Time: 4:28:15 PM
 */
public class Scan {

    private Map misses = new HashMap();
    private Miss[] values = null;
    private Project project = null;

    public Scan(Project p){
        this.project = p;
    }

    public void add(Occurrence occ)
    {
        Miss miss = (Miss)misses.get(occ.getWord());
        if(miss == null)
        {
            miss = new Miss(occ.getWord());
        }
        if(project.isWordIgnored(occ.getWord()) == false)
        {
            miss.add(occ);
            misses.put(miss.getWord(), miss);
        }
    }

    public void clean()
    {
        misses.clear();
        values = null;
    }

    public void iterate()
    {
        ArrayList list = new ArrayList();
        Iterator iterator = misses.keySet().iterator();
        while(iterator.hasNext())
        {
            String key = (String)iterator.next();
            list.add((Miss)misses.get(key));
        }
        values = new Miss[list.size()];
        list.toArray(values);
    }

    public int size(){
        return values.length;
    }

    public Miss get(int i)
    {
        return (Miss)values[i];
    }

    public Miss get(String word)
    {
        return (Miss)misses.get(word);
    }
}

/*  
 *  $Log:  $ 
 */
